<template>
  <div style="width: 100%">

    <el-row>
      <el-col :span="24">
        <div style="background: #42464b;height: 60px">
          <span style="color: white;margin-left: 20px;font-size: 25px;line-height: 60px">进销存管理系统</span>
        </div>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="4">
        <el-menu
            active-text-color="#ffd04b"
            background-color="#545c64"
            class="el-menu-vertical-demo"
            default-active="2"
            text-color="#fff"
            @open="handleOpen"
            @close="handleClose"
            style="height: 100%"
        >
          <!--资料管理-->
          <el-sub-menu index="1" v-if="isNotShow('供应商管理','客户管理')">
            <template #title>
              <el-icon>
                <location/>
              </el-icon>
              <span>资料管理</span>
            </template>
            <el-menu-item-group class="test">
              <el-menu-item index="1-1" v-if="isNotShow('供应商管理')" @click="$router.push('/index/supplier')">
                供应商管理
              </el-menu-item>

              <el-menu-item index="1-2" v-if="isNotShow('客户管理')" @click="$router.push('/index/client')">
                客户管理
              </el-menu-item>

            </el-menu-item-group>
          </el-sub-menu>
          <!-- 采购管理-->
          <el-sub-menu index="2" v-if="isNotShow('采购入库','采购信息查询')">
            <template #title>
              <el-icon>
                <location/>
              </el-icon>
              <span>采购管理</span>
            </template>
            <el-menu-item-group class="test">
              <el-menu-item index="2-1" v-if="isNotShow('采购入库')" @click="$router.push('/index/buyerCar')">
                采购入库
              </el-menu-item>
              <el-menu-item index="2-2" v-if="isNotShow('采购信息查询')" @click="$router.push('/index/buyerInfo')">
                采购信息查询
              </el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>
          <!-- 销售管理-->
          <el-sub-menu index="3" v-if="isNotShow('销售出库','销售信息查询')">
            <template #title>
              <el-icon>
                <location/>
              </el-icon>
              <span>销售管理</span>
            </template>
            <el-menu-item-group class="test">
              <el-menu-item index="3-1" v-if="isNotShow('销售出库')" @click="$router.push('/index/sellCar')">
                销售出库
              </el-menu-item>
              <el-menu-item index="3-2" v-if="isNotShow('销售信息查询')" @click="$router.push('/index/sellInfo')">
                销售信息查询
              </el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>

          <!-- 库存管理-->
          <el-sub-menu index="4"  v-if="isNotShow('库存一览')">
            <template #title>
              <el-icon>
                <location/>
              </el-icon>
              <span>库存管理</span>
            </template>
            <el-menu-item-group class="test">
              <el-menu-item index="4-1" v-if="isNotShow('库存一览')" @click="$router.push('/index/product')">
                库存一览
              </el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>

          <!-- 统计信息-->
          <el-sub-menu index="5" v-if="isNotShow('销售统计','客户统计')">
            <template #title>
              <el-icon>
                <location/>
              </el-icon>
              <span>统计信息</span>
            </template>
            <el-menu-item-group class="test">
              <el-menu-item index="5-1" v-if="isNotShow('销售统计')" @click="$router.push('/index/countAll')">
                销售统计
              </el-menu-item>
              <el-menu-item index="5-2" v-if="isNotShow('月销售统计')" @click="$router.push('/index/countMonth')">
                月销售统计
              </el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>

          <!-- 权限管理-->
          <el-sub-menu index="6" v-if="isNotShow('用户管理','角色管理')">
            <template #title>
              <el-icon>
                <location/>
              </el-icon>
              <span>权限管理</span>
            </template>
            <el-menu-item-group class="test">
              <el-menu-item index="6-1" v-if="isNotShow('用户管理')" @click="$router.push('/index/user')">
                用户管理
              </el-menu-item>
              <el-menu-item index="6-2" v-if="isNotShow('角色管理')" @click="$router.push('/index/role')">
                角色管理
              </el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>

          <!--修改密码-->
          <el-menu-item-group class="test">
            <el-menu-item index="7-1" @click="$router.push('/index/update')" style="padding-left: 48px">
              修改密码
            </el-menu-item>
          </el-menu-item-group>

          <!--日志一览-->
          <el-menu-item-group class="test">
            <el-menu-item index="8-1" v-if="isNotShow('日志一览')" @click="$router.push('/index/log')" style="padding-left: 48px">
              日志一览
            </el-menu-item>
          </el-menu-item-group>


        </el-menu>

      </el-col>

      <el-col :span="20">
        <router-view/>
      </el-col>
    </el-row>

  </div>

</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      loginUser: {},
      gradeList: [],
    }
  },
  methods: {
    async getLoginUser() {
      await axios.get("/project/user/getLoginUser").then(resp => {
        this.loginUser = resp.data;
      });
      this.getGradeList();
    },
    getGradeList() {
      this.loginUser.gradeSet.forEach(n => {
        this.gradeList.push(n.name)
      })
    },
    isNotShow(obj){
      var index=this.gradeList.findIndex(n=> n == obj);
      return index !=-1;
    }
  },
  created() {
    this.getLoginUser();
  }
}
</script>

<style scoped>
.test {
  margin-top: -21px;
}
</style>